<template>
  <el-header>

    <div class="l-content">
      <el-button size="small" plain @click="handleCollapse">
        <el-icon :size="20">
          <Menu></Menu>
        </el-icon>
      </el-button>

      <!--面包屑-->
      <el-breadcrumb separator="/" class="bread">
        <!--首页是一定存在的所以直接写死-->
        <el-breadcrumb-item :to="{ path: '/' }">
          首页
        </el-breadcrumb-item>

        <el-breadcrumb-item :to="current.path" v-if="current">
          {{ current.label }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img class="user" :src="imgSrc" alt="">
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item>退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>

  </el-header>
</template>

<script>
import {Menu} from "@element-plus/icons-vue";
import {useStore} from 'vuex'
import {computed} from "vue";

export default {
  name: "CommonHeader",
  components: {Menu},
  setup() {
    let store = useStore()

    const imgSrc = require('../assets/images/user.png')

    let handleCollapse = () => {
      store.commit("updateIsCollapse");
    }

    //面包屑
    const current = computed(() => {
      return store.state.currentMenu;
    })

    return {
      imgSrc,
      store,
      handleCollapse,
      current
    }
  }
}
</script>

<style lang="less" scoped>
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: #333;
}

.r-content {
  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}

.l-content {
  display: flex;
  align-items: center;

  .el-button {
    margin-right: 20px;
  }

  h3 {
    color: #fff;
  }
}

:deep(.bread span) {
  color: #fff !important;
  cursor: pointer !important;
}
</style>